import {
  Inject, Post, Body
} from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderOrderEntity } from '../../entity/order';
import { OrderOrderService } from '../../service/order';
import { UserInfoEntity } from '../../../user/entity/info';
import { NursingPersonEntity } from '../../../nursing/entity/person'
import { AddressInfoEntity } from '../../../address/entity/info'
import { NurseInfoEntity } from '../../../nurse/entity/info'
import { get } from 'http';

/**
 * 订单信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderOrderEntity,
  service: OrderOrderService,
  pageQueryOp: {
    fieldEq: ['a.orderNum', 'a.userId'],
    keyWordLikeFields: ['a.consignee', 'a.phoneNumber'],
    fieldLike: [],
    // fieldEq: [
    //   { column: 'a.status', requestParam: 'status' },
    //   { column: 'a.payType', requestParam: 'payType' },
    // ],
    // where: ctx => {
    //   const { createTime } = ctx.request.body;
    //   if (createTime && createTime.length === 2) {
    //     return [
    //       [
    //         'a.createTime BETWEEN :start AND :end',
    //         { start: createTime[0], end: createTime[1] },
    //       ],
    //     ];
    //   }
    // },
    select: ['a.*', 'b.name as beNurseName', 'c.province', 'c.city', 'c.district', 'c.detailAddress', 'd.nickName','d.phone', 'f.name as nurseName'],
    join: [
      {
        entity: NursingPersonEntity,
        alias: 'b',
        condition: 'a.beNurseId = b.id',
        type: 'leftJoin',
      },
      {
        entity: AddressInfoEntity,
        alias: 'c',
        condition: 'a.beNurseAddressId = c.id',
        type: 'leftJoin',
      },
      {
        entity: UserInfoEntity,
        alias: 'd',
        condition: 'a.openid = d.unionid',
        type: 'leftJoin',
      },
      {
        entity: NurseInfoEntity,
        alias: 'f',
        condition: 'a.nurseId = f.id',
        type: 'leftJoin',
      }
    ],
  },
})
export class AdminOrderOrderController extends BaseController {
  @Inject()
  orderOrderService: OrderOrderService;

  @Post("/updateOrderNursing", { summary: "生成订单" })
  async updateOrderNursing(@Body() BodyData: any) {
    let res = await this.orderOrderService.updateOrderNursing(BodyData)
    return res;
  }
}
